<?php
/**
 * @name Action
 *
 * LICENSE
 *
 * This source file is subject to the BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.phpxe.com/license/
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to Chaodong.Sheng <scd113@gmail.com> so we can send you a copy immediately.
 *
 * @category   Controller of Scd Framework
 * @package    Scd
 * @copyright  Copyright (c) 2007 PHPXe Web Studio <http://www.phpxe.com>
 * @license    http://framework.phpxe.com/license/
 * @version    $Id:$
 */
include_once('Scd/Controller/Exception.php');
class Scd_Controller_Action {

	var $pdo	= null;
	var $view	= null;
	var $_post	= null;

	var $_filter;
	//预留，不知道做什么用好
	var $dipIns	= false;

	function Scd_Controller_Action($dispatchIns) {
		$this->setDipIns( $dispatchIns );
		$this->_filter = $dispatchIns->_filter->getInstance(array('div'), array('style'), 1, 0, 1);
		Scd::loadClass("scd.factory");
		$f = new Scd_Factory(new Sonfig());
		//$this->_post = Scd_Filter_InputFilter::getInstance();
		$this->view = $f->getTemplate();
		$this->pdo = $f->getDBO();
	}

	/**
	 * 获得$_POST
	 * @return boolean | $_POST
	 */
	function getPost()
	{
		if (!isset($_POST)) {
			return null;
		}
		return $this->_post = $this->_clean($_POST);
	}
	
	/**
	 * 存储dispatchIns
	 */
	function setDipIns($ins)
	{
		if (false == $this->dipIns) {
			$this->dipIns = $ins;
		}
	}
	
	/**
	 * Filter
	 * 为应用方便提供一个Filter
	 * @param $source:Input string/array-of-string to be 'cleaned'
	 * @param $type:0,一般信息过滤,也去除了<div>[默认]	1,严格过滤到planitTXT
	 */
	function _clean( $source, $type = 0 )
	{
		switch ($type) {
			case 1:		//严格过滤
				$source = $this->dipIns->_filter->clean($source);
				break;
		
			case 0:
			default:
				$source = $this->_filter->clean($source);
				break;
		}
		return $source;
	}
	
	/**
	 * Smarty 赋值
	 *
	 */
	function viewAssign($key, $value)
	{
		return $this->view->set($key, $value);
	}
	
	/**
	 * 显示
	 *
     * @param  string|null $action Defaults to action registered in request object
     * @param  string|null $name Response object named path segment to use; defaults to null
	 */
	function render($name)
	{
		$this->viewAssign('siteName', $this->dipIns->_confIns->siteName);
		$this->viewAssign('siteUri', $this->dipIns->_confIns->siteUri);
		$this->viewAssign('siteInfo', $this->dipIns->_confIns->siteInfo);
		$this->view->display($name);
		//$script = $this->getViewScript($action);
	}
}
